package tt.dz.appserver.util;

import org.springframework.util.StringUtils;

import tt.dz.appserver.util.dzcode.BaseCode;
import tt.dz.appserver.util.dzcode.MainServerCode;
import tt.dz.appserver.util.dzcode.OmsCode;
import tt.dz.appserver.util.enums.Response;

/**
 * 相应码帮助类
 * 
 * @author xielf
 *
 */
public final class CodeUtils {

	/**
	 * 主服务器响应码匹配码
	 * 
	 * @param code
	 * @return
	 */
	public static final Response getCodeByMainServerCode(String code) {

		Response response = null;
		if (StringUtils.isEmpty(code)) {
			return Response.RUNTIME_ERROR;
		}
		switch (code) {
		case MainServerCode.USER_NOT_FOUND:
			response = Response.USER_NOT_FOUND;
			break;
		case MainServerCode.USERID_OR_CARDNO_IS_NULL:
			response = Response.USERID_OR_CARDNO_IS_NULL;
			break;
		case MainServerCode.IS_NOT_ENTUSER:
			response = Response.IS_NOT_ENTUSER;
			break;
		case MainServerCode.IS_NOT_VALID:
			response = Response.IS_NOT_VALID;
			break;
		case MainServerCode.ROLE_EXISTS:
			response = Response.ROLE_EXISTS;
			break;
		case MainServerCode.OPER_EXISTS:
			response = Response.OPER_EXISTS;
			break;
		case MainServerCode.ROLE_NOT_FOUNT:
			response = Response.ROLE_NOT_FOUNT;
			break;
		case MainServerCode.SAVE_UNKNOWN_ERROR:
			response = Response.SAVE_UNKNOWN_ERROR;
			break;
		case MainServerCode.BAD_PWD:
			response = Response.BAD_PWD;
			break;
		case MainServerCode.USER_LOCKED:
			response = Response.USER_LOCKED;
			break;
		case MainServerCode.BAD_SMS_CODE:
			response = Response.VERIFY_CODE_ERROR;
			break;
		case MainServerCode.REPEAT_PWD_ERROR:
			response = Response.REPEAT_PWD_ERROR;
			break;
		case MainServerCode.BAD_PARAM_VERIFY:
			response = Response.BAD_PARAM_VERIFY;
			break;
		case MainServerCode.NO_PASSWORD_SETTED:
			response = Response.NO_PASSWORD_SETTED;
			break;
		case MainServerCode.CARD_NOT_FOUND:
			response = Response.CARD_NOT_FOUND;
			break;
		case MainServerCode.NOT_ACTIVITY:
			response = Response.NOT_ACTIVITY;
			break;
		case MainServerCode.FROZED:
			response = Response.FROZED;
			break;
		case MainServerCode.RECORD_LOST:
			response = Response.RECORD_LOST;
			break;
		case MainServerCode.CANCELLED:
			response = Response.CANCELLED;
			break;
		case MainServerCode.OVER_TIMED:
			response = Response.OVER_TIMED;
			break;
		case MainServerCode.CARD_NO_IS_NULL:
			response = Response.CARD_NO_IS_NULL;
			break;
		case MainServerCode.IDENTITY_CARD_UN_EXIST:
			response = Response.IDENTITY_CARD_UN_EXIST;
			break;
		case MainServerCode.CARD_TYPE_NOT_EXIST:
			response = Response.CARD_TYPE_NOT_EXIST;
			break;
		case MainServerCode.CARD_TYPE_ERROR:
			response = Response.CARD_TYPE_ERROR;
			break;
		case MainServerCode.PARTNER_NOT_FOUND:
			response = Response.PARTNER_NOT_FOUND;
			break;
		case MainServerCode.MERCHANT_IS_REQUIRED:
			response = Response.MERCHANT_IS_REQUIRED;
			break;
		case MainServerCode.PAY_STATE_ERROR:
			response = Response.PAY_STATE_ERROR;
			break;
		case MainServerCode.SAVE_TRAN_INFO_FAIL:
			response = Response.SAVE_TRAN_INFO_FAIL;
			break;
		case MainServerCode.SAVE_TRAN_SUB_INFO_FAIL:
			response = Response.SAVE_TRAN_SUB_INFO_FAIL;
			break;
		case MainServerCode.SERVICE_NOT_FOUND:
			response = Response.SERVICE_NOT_FOUND;
			break;
		case MainServerCode.PAY_AMOUNT_ERROR:
			response = Response.PAY_AMOUNT_ERROR;
			break;
		case MainServerCode.PAYTYPE_NOTMATCH_USERTYPE:
			response = Response.PAYTYPE_NOTMATCH_USERTYPE;
			break;
		case MainServerCode.PAYTYPE_NOTMATCH_TRADETYPE:
			response = Response.PAYTYPE_NOTMATCH_TRADETYPE;
			break;
		case MainServerCode.CHANNEL_NOT_FOUNT:
			response = Response.CHANNEL_NOT_FOUNT;
			break;
		case MainServerCode.PARAM_REQUIRED:
			response = Response.PARAM_REQUIRED;
			break;
		case MainServerCode.FORMAT_ERROR:
			response = Response.FORMAT_ERROR;
			break;
		case MainServerCode.PARAM_TOO_LARGE:
			response = Response.PARAM_TOO_LARGE;
			break;
		case MainServerCode.SYSCODE_NOT_FOUNT:
			response = Response.SYSCODE_NOT_FOUNT;
			break;
		case MainServerCode.CREATEBY_NOT_FOUNT:
			response = Response.CREATEBY_NOT_FOUNT;
			break;
		case MainServerCode.PARAM_FORMAT_ERROT:
			response = Response.PARAM_FORMAT_ERROT;
			break;
		case MainServerCode.MESSAGE_SEND_ERROR:
			response = Response.MESSAGE_SEND_ERROR;
			break;
		case MainServerCode.SAVE_ERROR:
			response = Response.SAVE_ERROR;
			break;
		case MainServerCode.CAN_NOT_MINUS:
			response = Response.CAN_NOT_MINUS;
			break;
		case MainServerCode.COMMON_EXCEPTION:
			response = Response.COMMON_EXCEPTION;
			break;

		case MainServerCode.MOBILE_NO_FORMAT_ERROR:
			response = Response.MOBILE_NO_FORMAT_ERROR;
			break;
		case MainServerCode.REPEAT_SEND_ERROR:
			response = Response.REPEAT_SEND_ERROR;
			break;
		case MainServerCode.NOT_SEND_SMS_CODE:
			response = Response.NOT_SEND_SMS_CODE;
			break;
		case MainServerCode.USER_EXISTS:
			response = Response.USER_EXISTS;
			break;
		case MainServerCode.BALANCE_NOT_ENOUGH:
			response = Response.BALANCE_NOT_ENOUGH;
			break;
		case MainServerCode.CASH_MUST_GREATER_THAN_ZERO:
			response = Response.CASH_MUST_GREATER_THAN_ZERO;
			break;
		case MainServerCode.PASSWORD_ERROR:
			response = Response.PASSWORD_ERROR;
			break;
		case MainServerCode.REPEAT_IS_BIND:
			response = Response.REPEAT_IS_BIND;
			break;
		default:
			response = Response.RUNTIME_ERROR;
			break;
		}

		return response;
	}

	/**
	 * 订单服务器相应码
	 * 
	 * @param code
	 * @return
	 */
	public static final Response getCodeByOrderServerCode(String code) {

		return Response.SUCCESS;
	}

	/**
	 * OMS响应码
	 * 
	 * @param code
	 * @return
	 */
	public static final Response getCodeByOMSServerCode(String code) {

		Response response = null;
		if (StringUtils.isEmpty(code)) {
			return Response.RUNTIME_ERROR;
		}
		switch (code) {
		
		case OmsCode.CHARGERESULTDUPLICATECHARGEINSTRUCTION:
			response = Response.CHARGERESULTDUPLICATECHARGEINSTRUCTION;
			break;
		case OmsCode.STATIONQUERYEXCEPTION:
			response = Response.STATIONQUERYEXCEPTION;
			break;
		case OmsCode.CHARGERQUERYNULL:
			response = Response.CHARGERQUERYNULL;
			break;
		case OmsCode.NETWORKTIMEOUT:
			response = Response.NETWORKTIMEOUT;
			break;
		case OmsCode.HTTPUNKNOWNERROR:
			response = Response.HTTPUNKNOWNERROR;
			break;
		case OmsCode.MISSPARAM:
			response = Response.MISSPARAM;
			break;
		case OmsCode.MESSAGEUNKNOWNERROR:
			response = Response.MESSAGEUNKNOWNERROR;
			break;
		case OmsCode.MESSAGEMISSPARAM:
			response = Response.MESSAGEMISSPARAM;
			break;
		case OmsCode.MESSAGEPARAMTYPEERROR:
			response = Response.MESSAGEPARAMTYPEERROR;
			break;
		case OmsCode.MESSAGEPARAMVALUEERROR:
			response = Response.MESSAGEPARAMVALUEERROR;
			break;
		case OmsCode.MESSAGEEXECERROR:
			response = Response.MESSAGEEXECERROR;
			break;
		case OmsCode.REDISQUERYNULL:
			response = Response.REDISQUERYNULL;
			break;
		case OmsCode.THREADEXCEPTION:
			response = Response.THREADEXCEPTION;
			break;
		case OmsCode.NULLEXCEPTION:
			response = Response.NULLEXCEPTION;
			break;
		case OmsCode.DATABASECONNECTIONEXCEPTION:
			response = Response.DATABASECONNECTIONEXCEPTION;
			break;
		case OmsCode.REDISCONNECTIONEXCEPTION:
			response = Response.REDISCONNECTIONEXCEPTION;
			break;
		case OmsCode.MIDDLECONNECTIONEXCEPTION:
			response = Response.MIDDLECONNECTIONEXCEPTION;
			break;
		case OmsCode.TELDCONNECTIONEXCEPTION:
			response = Response.TELDCONNECTIONEXCEPTION;
			break;
//		case OmsCode.ASCONNECTIONEXCEPTION:
//			response = Response.ASCONNECTIONEXCEPTION;
//			break;
//		case OmsCode.OSCONNECTIONEXCEPTION:
//			response = Response.OSCONNECTIONEXCEPTION;
//			break;
//		case OmsCode.MSCONNECTIONEXCEPTION:
//			response = Response.MSCONNECTIONEXCEPTION;
//			break;
		case OmsCode.SQLQUERYEXCEPTION:
			response = Response.SQLQUERYEXCEPTION;
			break;
		case OmsCode.SQLEXECEXCEPTION:
			response = Response.SQLEXECEXCEPTION;
			break;
		case OmsCode.BESPEAKRESULTCHARGERBESPEAKED:
			response = Response.BESPEAKRESULTCHARGERBESPEAKED;
			break;
		case OmsCode.CONNECTIONRESULTCHARGEREXCEPTION:
			response = Response.CONNECTIONRESULTCHARGEREXCEPTION;
			break;
//		case OmsCode.CANCELBESPEAKRESULTNOBESPEAK:
//			response = Response.CANCELBESPEAKRESULTNOBESPEAK;
//			break;
		case OmsCode.CHARGERESULTCLOSECHARGERFAIL:
			response = Response.CHARGERESULTCLOSECHARGERFAIL;
			break;
//		case OmsCode.STOPCHARGERESULTCONNECTIONEXCEPTION:
//			response = Response.STOPCHARGERESULTCONNECTIONEXCEPTION;
//			break;
		case OmsCode.BESPEAKRESULTEXISTNOTPAYORDER:
			response = Response.BESPEAKRESULTEXISTNOTPAYORDER;
			break;
		case OmsCode.QUERYENTERPRISEUSERNULL:
			response = Response.QUERYENTERPRISEUSERNULL;
			break;
//		case OmsCode.STATION_QUERY_ERROR:
//			response = Response.STATION_QUERY_ERROR;
//			break;
		case OmsCode.CHARGER_QUERY_ERROR:
			response = Response.CHARGER_QUERY_ERROR;
			break;
		case OmsCode.OTHER_LOGIN_ERROR:
			response = Response.OTHER_LOGIN_ERROR;
			break;
		case OmsCode.OTHER_LOCK_ERROR:
			response = Response.OTHER_LOCK_ERROR;
			break;
		case OmsCode.OL_NO_POWER_ACCESS_ERROR:
			response = Response.OL_NO_POWER_ACCESS_ERROR;
			break;
		case OmsCode.MS_RPC_ERROR:
			response = Response.MS_RPC_ERROR;
			break;
		case OmsCode.SYSTEM_ERROR:
			response = Response.SYSTEM_ERROR;
			break;
		case OmsCode.OTHER_LOGIN_CHANNEL_NO_ERROR:
			response = Response.OTHER_LOGIN_CHANNEL_NO_ERROR;
			break;
		case OmsCode.OL_REQUEST_PARAM_MISS_ERROR:
			response = Response.OL_REQUEST_PARAM_MISS_ERROR;
			break;
		case OmsCode.OL_TOKEN_OUTTIME_ERROR:
			response = Response.OL_TOKEN_OUTTIME_ERROR;
			break;
		case OmsCode.OL_TOKEN_AUTH_FAIL_ERROR:
			response = Response.OL_TOKEN_AUTH_FAIL_ERROR;
			break;
//		case OmsCode.SESSION_TIME_OUT:
//			response = Response.SESSION_TIME_OUT;
//			break;
//		case OmsCode.HTTP_UNKNOW_ERROR:
//			response = Response.HTTP_UNKNOW_ERROR;
//			break;
//		case OmsCode.REQUEST_PARAM_MISS_ERROR:
//			response = Response.REQUEST_PARAM_MISS_ERROR;
//			break;
		case OmsCode.HTTP_PARAM_TYPE_ERROR:
			response = Response.HTTP_PARAM_TYPE_ERROR;
			break;
		case OmsCode.HTTP_PARAM_VALUE_ERROR:
			response = Response.HTTP_PARAM_VALUE_ERROR;
			break;
//		case OmsCode.MESSAGE_UNKNOW_ERROE:
//			response = Response.MESSAGE_UNKNOW_ERROE;
//			break;
//		case OmsCode.MESSAGE_PARAM_MISS_ERROE:
//			response = Response.MESSAGE_PARAM_MISS_ERROE;
//			break;
//		case OmsCode.MESSAGE_PARAM_TYPE_ERROE:
//			response = Response.MESSAGE_PARAM_TYPE_ERROE;
//			break;
//		case OmsCode.MESSAGE_PARAM_VALUE_ERROE:
//			response = Response.MESSAGE_PARAM_VALUE_ERROE;
//			break;
//		case OmsCode.MESSAGE_PARAM_OPTION_ERROE:
//			response = Response.MESSAGE_PARAM_OPTION_ERROE;
//			break;
//		case OmsCode.JAVA_REDIS_QUERY_ERROE:
//			response = Response.JAVA_REDIS_QUERY_ERROE;
//			break;
//		case OmsCode.JAVA_THREAD_ERROE:
//			response = Response.JAVA_THREAD_ERROE;
//			break;
//		case OmsCode.JAVA_NULL_POINTER_ERROE:
//			response = Response.JAVA_NULL_POINTER_ERROE;
//			break;
//		case OmsCode.JAVA_DB_CONNECTION_ERROE:
//			response = Response.JAVA_DB_CONNECTION_ERROE;
//			break;
//		case OmsCode.JAVA_REDIS_CONNECTION_ERROE:
//			response = Response.JAVA_REDIS_CONNECTION_ERROE;
//			break;
//		case OmsCode.JAVA_MIDDLEWARE_CONNECTION_ERROE:
//			response = Response.JAVA_MIDDLEWARE_CONNECTION_ERROE;
//			break;
//		case OmsCode.JAVA_TELAIDIAN_CONNECTION_ERROE:
//			response = Response.JAVA_TELAIDIAN_CONNECTION_ERROE;
//			break;
		case OmsCode.JAVA_AS_CONNECTION_ERROE:
			response = Response.JAVA_AS_CONNECTION_ERROE;
			break;
		case OmsCode.JAVA_OS_CONNECTION_ERROE:
			response = Response.JAVA_OS_CONNECTION_ERROE;
			break;
		case OmsCode.JAVA_MS_CONNECTION_ERROE:
			response = Response.JAVA_MS_CONNECTION_ERROE;
			break;
//		case OmsCode.JAVA_DB_QUERY_ERROE:
//			response = Response.JAVA_DB_QUERY_ERROE;
//			break;
//		case OmsCode.JAVA_DB_EXEC_ERROE:
//			response = Response.JAVA_DB_EXEC_ERROE;
//			break;
		case OmsCode.AS_RPC_PARAM_FORMAT_ERROR:
			response = Response.AS_RPC_PARAM_FORMAT_ERROR;
			break;
		case OmsCode.AS_RPC_PARAM_TYPE_ERROR:
			response = Response.AS_RPC_PARAM_TYPE_ERROR;
			break;
		case OmsCode.AS_RPC_PARAM_EMPTY_ERROR:
			response = Response.AS_RPC_PARAM_EMPTY_ERROR;
			break;
		case OmsCode.AS_RPC_SERVER_ERROR:
			response = Response.AS_RPC_SERVER_ERROR;
			break;
		case OmsCode.OTHER_LOGIN_SUCCESS:
			response = Response.OTHER_LOGIN_SUCCESS;
			break;
		case OmsCode.GET_RESERVATION_DISCOUNT_ERROR:
			response = Response.GET_RESERVATION_DISCOUNT_ERROR;
			break;
		/** =========================OMS指令============================= */
//		case OmsCode.UNKNOWNERROR:
//			response = Response.UNKNOWNERROR;
//			break;
//		case OmsCode.MISSPARAMETER:
//			response = Response.MISSPARAMETER;
//			break;
//		case OmsCode.PARAMTYPEERROR:
//			response = Response.PARAMTYPEERROR;
//			break;
//		case OmsCode.PARAMVALUEERROR:
//			response = Response.PARAMVALUEERROR;
//			break;
		case OmsCode.NORMAL:
			response = Response.NORMAL;
			break;
		case OmsCode.OTHERFAULT:
			response = Response.OTHERFAULT;
			break;
		case OmsCode.EMERGENCYSTOP:
			response = Response.EMERGENCYSTOP;
			break;
		case OmsCode.AMMETER:
			response = Response.AMMETER;
			break;
		case OmsCode.SWITCHES:
			response = Response.SWITCHES;
			break;
		case OmsCode.CARDREADER:
			response = Response.CARDREADER;
			break;
		case OmsCode.OVERTEMPERATURE:
			response = Response.OVERTEMPERATURE;
			break;
		case OmsCode.CONNECTOR:
			response = Response.CONNECTOR;
			break;
		case OmsCode.ISOLATION:
			response = Response.ISOLATION;
			break;
		case OmsCode.OUTPUTCURRENTABNORMAL:
			response = Response.OUTPUTCURRENTABNORMAL;
			break;
		case OmsCode.OUTPUTVOLTAGEABNORMAL:
			response = Response.OUTPUTVOLTAGEABNORMAL;
			break;
		case OmsCode.CHARGERMODULE:
			response = Response.CHARGERMODULE;
			break;
		case OmsCode.CHARGERCOMMUNICATION:
			response = Response.CHARGERCOMMUNICATION;
			break;
		case OmsCode.BMSPROHIBITCHARGE:
			response = Response.BMSPROHIBITCHARGE;
			break;
		case OmsCode.INPUTVOLTAGEABNORMAL:
			response = Response.INPUTVOLTAGEABNORMAL;
			break;
		default:
			response = Response.RUNTIME_ERROR;
			break;

		}

		return response;
	}

	public static final Response getCodeByBasePatCode(Integer code) {

		Response response = null;
		if (StringUtils.isEmpty(code)) {
			return Response.RUNTIME_ERROR;
		}
		switch (code) {
		case BaseCode.CONNECTION_MS_FAILED:
			response = Response.CONNECTION_MS_FAILED;
			break;

		case BaseCode.EXPIRED_TOKEN:
			response = Response.EXPIRED_TOKEN;
			break;
		case BaseCode.INVALID_TOKEN:
			response = Response.INVALID_TOKEN;
			break;

		case BaseCode.MISSING_PARAMETERS:
			response = Response.MISSING_PARAMETERS;
			break;

		case BaseCode.NOT_FOUND:
			response = Response.NOT_FOUND;
			break;
		case BaseCode.RETRY_LOGIN:
			response = Response.RETRY_LOGIN;
			break;
		case BaseCode.VERIFY_TOKEN_FAILED:
			response = Response.VERIFY_TOKEN_FAILED;
			break;
		default:
			response = Response.RUNTIME_ERROR;
			break;
		}
		return response;
	}
	
}
